package com.manager.common.lock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @ClassName DecisionLock
 * @Description TODO
 * @Author @LiuHongJun
 * @Date 2025-10-21 9:39
 * @Version 1.0
 */
public class DecisionLock {

    private static DecisionLock decisionLock = new DecisionLock();
    private final static ReentrantLock lock = new ReentrantLock();
    private long lastTime = -1;//毫秒
    private int offset = 10; //秒

    private DecisionLock (){

    }

    public DecisionLock getInstance(){
        return decisionLock;
    }

    public boolean canGatherDecisionLog(int time){
        lock.lock();
        try {
            if(lastTime - System.currentTimeMillis() < 0){
                return false;
            }
            lastTime = System.currentTimeMillis() + (time + offset) * 1000;
        }finally {
            lock.unlock();
        }
        return true;
    }


}
